﻿namespace ReactionGame
{
    internal class Program
    {
        /// <summary>
        /// 打字游戏
        /// </summary>
        /// <param name="args"></param>
        enum Direction
        {
            down,
            up,
            left,
            right,
        }
        static void Main(string[] args)
        {
            //定义变量输出错误次数,耗时
            int Errors = 0, ReactionTime = 0;
            //定义测试次数
            Console.WriteLine("请输入测试次数");
            int CountOfTest = int.Parse(Console.ReadLine());
            Random rnd = new Random();
            //开始计时
            DateTime StartTime = DateTime.Now;
            for (int i = 0; i < CountOfTest; i++)
            {
                //清屏
                Console.Clear();
                //设置随机数
                Direction direction = (Direction)rnd.Next(1, 4);
                Console.WriteLine(direction.ToString());
                bool flag = false;
                Console.WriteLine($"当前运行第{i+1}次，错误{Errors}次");
                //定义input，与对应按键相比是否正确
                var input = Console.ReadKey();
                switch (direction)
                {
                    case Direction.down:
                        if (input.Key == ConsoleKey.DownArrow)
                            flag = true;
                        break;
                    case Direction.up:
                        if (input.Key == ConsoleKey.UpArrow)
                            flag = true;
                        break;
                    case Direction.left:
                        if (input.Key == ConsoleKey.LeftArrow)
                            flag = true;
                        break;
                        case Direction.right:
                        if (input.Key == ConsoleKey.RightArrow)
                            flag = true;
                        break;
                    default:
                        break;
                }
                if (flag == false)
                    Errors++;
            }
            //结束计时
            DateTime EndTime = DateTime.Now;
            //计算时间
            ReactionTime = (int)(EndTime - StartTime).TotalSeconds;
            //输出结果
            Console.WriteLine($"共运行{CountOfTest}次,当前总用时{ReactionTime}秒,共错误{Errors}次");
        }
    }
}